<?php

namespace App\Http\Controllers;

use App\Library\Lock;
use App\Library\Requests\ZbCash\ZbCashPaymentRequest;
use App\Library\Service\ZbBailService;
use Illuminate\Http\JsonResponse;

class ZbBailController extends BaseController
{
    public function __construct(ZbBailService $service)
    {
        $this->service = $service;
    }

    /**
     * 拉起支付
     * @param ZbCashPaymentRequest $request
     * @return JsonResponse
     */
    public function payment(ZbCashPaymentRequest $request): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . USERID, function () use ($request) {
            return $this->service->payment($request);
        });
    }

    /**
     * 退款
     * @return JsonResponse
     */
    public function refund(): JsonResponse
    {
        return Lock::get(__CLASS__ . __FUNCTION__ . USERID, function () {
            return $this->service->refund();
        });
    }

    /**
     * 状态
     * @return JsonResponse
     */
    public function current(): JsonResponse
    {
        return $this->service->current();
    }
}
